package com.huangliusong.aop.deme1;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class MyJdkProxy implements InvocationHandler {
    private UserDao userDao;
    public MyJdkProxy(UserDao userDao){
        System.out.println("构造函数======================================");
        this.userDao=userDao;
    }
    public Object createProxy(){
        System.out.println("createProxy===================================");
        Object p=Proxy.newProxyInstance(userDao.getClass().getClassLoader(),userDao.getClass().getInterfaces(),this);
        return p;
    }

    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        if("save".equals(method.getName())){
            System.out.println("代码增强--权限校验");
        }
        return method.invoke(userDao,args);
    }
}
